<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core">

<h:head>
	<title>Sistema Financeiro</title>
	<h:outputText value="#{usuarioMBean.loginUsuario}" />
	<a href="/Financeiro/j_spring_security_logout"> Sair </a>
</h:head>

<h:body>
	<h:messages />
	<div align="left">
		<h1>Cadastro de Usuario</h1>

		<h:form id="usuarioForm">


			<table>
				<tr>
					<td>Nome:</td>
					<td><h:inputText value="#{ usuarioMBean.obj.nome }" size="50"
							required="true" requiredMessage="Nome: obrigatorio." /></td>
				</tr>
				<tr>
					<td>Login:</td>
					<td><h:inputText value="#{ usuarioMBean.obj.login }" size="12"
							required="true"
							requiredMessage="Login: Campo obrigatorio ou invalido.">
							<f:validateRegex pattern="[a-zA-Z0-9_]+" />
						</h:inputText></td>
				</tr>
				<tr>
					<td>Senha:</td>
					<td><h:inputSecret value="#{usuarioMBean.obj.senha}" size="12"
							required="true" requiredMessage="Senha: obrigatorio." /></td>
				</tr>
				<tr>
					<td>Ativo?:</td>
					<td><h:selectOneRadio required="true"
							value="#{usuarioMBean.obj.ativo}">
							<f:selectItem id="ativo" itemLabel="Sim" itemValue="true" />
							<f:selectItem id="inativo" itemLabel="Não" itemValue="false" />
						</h:selectOneRadio></td>
				</tr>
				<tr>
					<td>Papel:</td>
					<td><h:selectOneMenu id="Papel"
							value="#{usuarioMBean.obj.permissoes}" var="permissao">
							<f:converter converterId="papelConverter"/>
							<f:selectItem itemLabel="-- SELECIONE --" />
							<f:selectItems value="#{papelMBean.listaPapel()}" var="papel"
								itemValue="#{papel}" itemLabel="#{papel.descricao}" />
						</h:selectOneMenu></td>
					<td><h:commandButton
							action="#{usuarioMBean.obj.addPermissao(papel)}"
							value="Adicionar Papel">
							</h:commandButton></td>
				</tr>
				<tr>
					<td colspan="2"><h:commandButton value="Cadastrar"
							action="#{usuarioMBean.salvar}"
							rendered="#{usuarioMBean.obj.id == 0}"/> <h:commandButton
							value="Atualizar" action="#{usuarioMBean.atualizar}"
							rendered="#{usuarioMBean.obj.id > 0}" /></td>
				</tr>
			</table>
			<h:commandButton action="#{usuarioMBean.menu}" value="Menu"
				immediate="true" />
		</h:form>

	</div>
</h:body>
</html>